package org.boyan.modules.auth.service.a;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

import org.boyan.common.system.vo.SysPermissionDataRuleModel;
import org.boyan.modules.auth.entity.OnlAuthData;
import org.boyan.modules.auth.entity.OnlAuthRelation;
import org.boyan.modules.auth.mapper.OnlAuthDataMapper;
import org.boyan.modules.auth.mapper.OnlAuthRelationMapper;
import org.boyan.modules.auth.service.IOnlAuthDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: zhuxiaobao
 * @time: 2021/9/24 16:38
 */

@Service("onlAuthDataServiceImpl")
public class a extends ServiceImpl<OnlAuthDataMapper, OnlAuthData> implements IOnlAuthDataService {
    @Autowired
    private OnlAuthRelationMapper onlAuthRelationMapper;

    @Override
    public void deleteOne(String id) {
        removeById(id);
        LambdaQueryWrapper<OnlAuthRelation> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(OnlAuthRelation::getAuthId, id);
        this.onlAuthRelationMapper.delete(lambdaQueryWrapper);
    }

    @Override
    public List queryUserOnlineAuthData(String userId, String cgformId) {
        List<SysPermissionDataRuleModel> list1 = this.baseMapper.queryRoleAuthData(userId, cgformId);
        List<SysPermissionDataRuleModel> list2 = this.baseMapper.queryDepartAuthData(userId, cgformId);
        List<SysPermissionDataRuleModel> list3 = this.baseMapper.queryUserAuthData(userId, cgformId);
        HashMap<Object, Object> hashMap = new HashMap<>();
        for (SysPermissionDataRuleModel sysPermissionDataRuleModel : list1) {
            String str = sysPermissionDataRuleModel.getId();
            hashMap.putIfAbsent(str, sysPermissionDataRuleModel);
        }
        for (SysPermissionDataRuleModel sysPermissionDataRuleModel : list2) {
            String str = sysPermissionDataRuleModel.getId();
            hashMap.putIfAbsent(str, sysPermissionDataRuleModel);
        }
        for (SysPermissionDataRuleModel sysPermissionDataRuleModel : list3) {
            String str = sysPermissionDataRuleModel.getId();
            hashMap.putIfAbsent(str, sysPermissionDataRuleModel);
        }
        Collection<Object> collection = hashMap.values();
        if (collection.size() == 0) {
            return null;
        }
        return new ArrayList(hashMap.values());
    }
}
